<template>
  <el-form-item
    :label="i18nt('designer.setting.labelAlign')"
    v-if="!noLabelSetting && selectedWidget.type !== 'button'"
  >
    <el-radio-group v-model="localOptionModel.labelAlign" class="radio-group-custom">
      <el-radio-button label="label-left-align">
        {{ i18nt('designer.setting.leftAlign') }}</el-radio-button
      >
      <el-radio-button label="label-center-align">
        {{ i18nt('designer.setting.centerAlign') }}</el-radio-button
      >
      <el-radio-button label="label-right-align">
        {{ i18nt('designer.setting.rightAlign') }}</el-radio-button
      >
    </el-radio-group>
  </el-form-item>
</template>

<script>
import i18n from '@/utils/i18n'
import { reactive, toRefs } from 'vue'
export default {
  name: 'LabelAlignEditor',
  mixins: [i18n],
  props: {
    designer: Object,
    selectedWidget: Object,
    optionModel: Object
  },
  data() {
    return {
      // Create a local copy of the prop to use with v-model
      localOptionModel: this.optionModel
    }
  },
  computed: {
    noLabelSetting() {
      return this.selectedWidget.type === 'static-text' || this.selectedWidget.type === 'html-text'
      //|| (this.selectedWidget.type === 'divider')
    }
  },
  watch: {
    // Watch for changes in the local model and emit an event to update the parent component
    localOptionModel(newValue) {
      this.$emit('update:optionModel', this.localOptionModel)
    },

    // Also make sure to update the local model if the prop changes externally
    optionModel(newVal) {
      this.localOptionModel = newVal
    }
  }
}
</script>

<style lang="scss" scoped>
.radio-group-custom {
  :deep(.el-radio-button__inner) {
    padding-left: 12px;
    padding-right: 12px;
  }
}
</style>
